import request from '@/utils/request'

interface LoginParams {
  userAccount: string
  userPassword: string
}

interface UserInfo {
  userId: number
  userAccount: string
  userName: string
  userAvatar?: string
  userRole: string
  createTime: string
}

interface LoginResponseData {
  tokenValue: string
  tokenName: string
  isLogin: boolean
  loginId: string
  loginType: string
  tokenTimeout: string
  sessionTimeout: string
  tokenSessionTimeout: string
  tokenActiveTimeout: string
  loginDevice: string
  tag: string | null
}

interface ApiResponse<T> {
  code: number
  data: T
  message: string
}

interface AxiosApiResponse<T> {
  data: ApiResponse<T>
  status: number
  statusText: string
  headers: Record<string, string>
  config: any
  request: any
}

// 登录
export const login = (data: LoginParams): Promise<AxiosApiResponse<LoginResponseData>> => {
  return request({
    url: '/user/login',
    method: 'post',
    data
  })
}

// 获取当前登录用户信息
export const getUserInfo = (): Promise<AxiosApiResponse<UserInfo>> => {
  return request({
    url: '/user/get/login',
    method: 'get'
  })
}

// 退出登录
export const logout = (): Promise<AxiosApiResponse<boolean>> => {
  return request({
    url: '/user/logout',
    method: 'post'
  })
} 